<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport"
        content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <script src="/web/js/global/global_header.js"></script>
    <title>华锐Pms</title>
</head>
<style>

</style>

<body>
    <div id="app" class="bgc-f2 pl-16 pr-16 pt-16 pb-10" v-cloak>
        <el-alert title="权限代码说明" type="warning" description="只有最后一级类目才需要设置权限代码。" show-icon class="mb-16">
        </el-alert>
        <el-tabs v-model="active" @tab-click="handleClick">
            <el-tab-pane label="功能权限" name="1"></el-tab-pane>
            <el-tab-pane label="菜单设置" name="2"></el-tab-pane>
        </el-tabs>

        <template>
            <div class="ub ub-ac ub-sb mb-16">
                <div class="tx-w" v-if="active == 1">功能权限</div>
                <div class="tx-w" v-if="active == 2">菜单权限</div>
                <div>
                    <el-button type="primary" size="small" @click="editClick({flag:active},0)" class="tx-14"
                        v-haspermi="['sys:permission:add']">添加授权
                    </el-button>
                </div>
            </div>
            <div>
                <el-table :data="tableData" style="width: 100%" border row-key="id"
                    :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
                    :header-cell-style="{background:'#eaedf4','color':'#333',padding:'8px 0'}">
                    <el-table-column prop="name" label="权限名称" width="200">
                    </el-table-column>
                    <el-table-column prop="code" label="权限代码" width="300">
                    </el-table-column>
                    <el-table-column prop="ord" label="排序">
                    </el-table-column>
                    <el-table-column fixed="right" label="操作" width="200">
                        <template slot-scope="scope">
                            <template v-if="scope.row.level != 2">
                                <el-button type="text" size="small" class="tx-bl tx-14 btn-br"
                                    v-haspermi="['sys:permission:add']" @click="editClick(scope.row,1)">
                                    新增
                                </el-button>
                            </template>
                            <el-button @click="editClick(scope.row)" type="text" size="small" class="tx-14 btn-br"
                                v-haspermi="['sys:permission:edit']">
                                编辑
                            </el-button>
                            <el-button type="text" size="small" class="tx-re tx-14 btn-br" @click="delClick(scope.row)"
                                v-haspermi="['sys:permission:del']">删除
                            </el-button>
                        </template>
                    </el-table-column>
                </el-table>
            </div>
        </template>
    </div>
    <script type="text/babel">
        window.vm = new Vue({
            el: '#app',
            data: {
                tableData: [],
                score: [],
                params: {},
                active: "1",
            },
            mounted() {
            },
            beforeCreate() {
                top.vm.startLoading("加载中")
            },
            created() {
                this.getList();
            },
            methods: {
                getList() {
                    this.GET({ url: top.Config.curUrl + "/sys/sysFunction/list", map: this.params }).then((res) => {
                        if (res.retcode == 200) { //如果返回码不是200则提示错误登录信息
                            this.score = JSON.parse(JSON.stringify(res.result.sysFunctionList))
                            if (this.active == 1) {
                                this.tableData = WebUtil.handleLevel(res.result.sysFunctionList.filter(item => item.flag == this.active || item.flag == 0), "id", "pid");
                            } else {
                                this.tableData = WebUtil.handleLevel(res.result.sysFunctionList.filter(item => item.flag == this.active), "id", "pid");
                            }
                        } else { //如果返回码是200则登录成功
                            this.msgError(res.retmsg)
                        }
                        top.vm.closeLoading();
                    })
                },
                // 编辑按钮
                editClick(row, isadd) {
                    this.openDetailsWin({
                        id: "permission_manage_edit",
                        params: { id: isadd ? "" : row.id || "", flag: row.flag, pid: isadd && row.id ? row.id : row.pid || "0" },
                        iframeUrl: "/web/view/permission/permission_manage_edit.html"
                    })
                },
                // 删除按钮
                delClick(row) {
                    let params = JSON.parse(JSON.stringify(row))
                    params.status = -1
                    this.confirm("您确认删除吗？").then(() => {
                        this.POST({ url: top.Config.curUrl + "/sys/sysFunction/save", map: params }).then((res) => {
                            if (res.retcode == 200) { //如果返回码不是200则提示错误登录信息
                                setTimeout(() => {
                                    this.getList();
                                    this.msgSuccess("删除成功");
                                }, 1000);
                            } else { //如果返回码是200则登录成功
                                this.msgError(res.retmsg);
                            }
                        })
                    })

                },
                handleClick() {
                    this.tableData = JSON.parse(JSON.stringify(this.score))
                    if (this.active == 1) {
                        this.tableData = WebUtil.handleLevel(this.tableData.filter(item => item.flag == this.active || item.flag == 0), "id", "pid");
                    } else {
                        this.tableData = WebUtil.handleLevel(this.tableData.filter(item => item.flag == this.active), "id", "pid");
                    }
                }
            }
        })

    </script>

</body>

</html>